﻿using System.Collections;
using RAP.Framework.Libary.Utils;
using static RAP.Framework.Libary.DataSource.ServiceUtils;

namespace RAP.Framework.Libary.DataSource.Context
{
  /// <summary>
  /// 查询参数对象
  /// </summary>
  public abstract class AbstractQueryParam : DynamicHashtable, IQueryParams
  {
    public AbstractQueryParam() { }

    public AbstractQueryParam(IDictionary param) : base(param)
    {

    }

    /// <summary>
    /// 无SQL模板时直接执行的SQL语句
    /// </summary>
    public string Sql { get; set; }

    /// <summary>
    /// 是否允许打开调试状态
    /// </summary>
    public bool AllowDebug { get; set; }

    /// <summary>
    /// 是否处于调试状态
    /// </summary>
    public bool Debug { get; set; }

    /// <summary>
    /// 模板的FullName
    /// </summary>
    public string TemplateId { get; set; }

    /// <summary>
    /// 返回的结果集类型：Table、DataSet、IDictionary
    /// </summary>
    public string DataType { get; set; }

    /// <summary>
    /// 默认数据源Id
    /// </summary>
    public string DataSource { get; set; }

    /// <summary>
    /// 默认是否开启事务
    /// </summary>
    public bool NeedTrans { get; set; }

    /// <summary>
    /// 查询是否允许空Sql，如果不允许，则抛出错误
    /// </summary>
    public bool AllowEmptySql { get; set; }

    /// <summary>
    /// 缓存的Key根名称
    /// </summary>
    public string CacheProxyKey { get; set; }

    /// <summary>
    /// 获取请求Body中的XML内容
    /// </summary>
    public string XMLContent { get => this.ToString("xml"); }

    /// <summary>
    /// 将当前查询参数对象复制到目标对象
    /// </summary>
    /// <param name="target"></param>
    /// <returns></returns>
    public virtual IQueryParams CopyTo(IQueryParams target)
    {
      return base.CopyTo<IQueryParams>(target);
    }

    /// <summary>
    /// 
    /// </summary>
    /// <param name="src"></param>
    /// <returns></returns>
    public virtual new IQueryParams CopyFrom(IDictionary src)
    {
      base.CopyFrom(src);
      return this;
    }
  }
}
